package ProjectYudisium;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.*;
import javax.swing.*;

public class PanelDaftarYudisium extends JPanel {

    private JLabel labelJudul, labelNim, labelNama, labelProdi, labelNomorHP,
            labelPeriode, kelengkapan, labelNilai, labelNaskahTA, labelPinjamLab, labelPinjamDosen,
            labelBuktiKP, labelSurat, labelFakultas, labelUpload;
    private JTextField dataNim, dataNama, dataNomorHP, dataPeriode;
    private JCheckBox daftarNilai, naskahTA, bebasPinjamLab, bebasPinjamDosen, buktiKP, suratKetKKLKI;
    private JRadioButton ff, fp, fst, fkip, fe, fs, ft;
    private JButton save, change, cancel, upload;
    private JCheckBox[] checkBox;
    private JFileChooser uploadFile;
    private JComboBox dataProdi, dataFakultas;

    PanelDaftarYudisium(ArrayList<Yudisium> DAFTAR_MAHASISWA) {
    }

    public PanelDaftarYudisium() {
        setLayout(null);
        setVisible(true);
        setSize(880, 580);

        labelJudul = new JLabel("*** Formulir Pendaftaran Yudisium USD Yogyakarta ***");
        labelJudul.setBounds(55, 0, 800, 100);
        labelJudul.setAlignmentX(CENTER_ALIGNMENT);
        labelJudul.setVisible(true);
        labelJudul.setFont(new Font("Broadway", 1, 24));
        add(labelJudul);

        labelNim = new JLabel("Nomor Induk Mahasiswa : ");
        labelNim.setBounds(70, 80, 250, 30);
        labelNim.setFont(new Font("Times New Roman", 1, 18));
        labelNim.setVisible(true);
        this.add(labelNim);

        dataNim = new JTextField();
        dataNim.setSize(15, 100);
        dataNim.setBounds(300, 80, 92, 30);
        dataNim.setFont(new Font("Times New Roman", 1, 17));
        dataNim.setVisible(true);
        this.add(dataNim);

        labelNama = new JLabel("Nama Lengkap Mahasiswa : ");
        labelNama.setBounds(70, 120, 250, 30);
        labelNama.setFont(new Font("Times New Roman", 1, 18));
        labelNama.setVisible(true);
        this.add(labelNama);

        dataNama = new JTextField();
        dataNama.setSize(15, 100);
        dataNama.setFont(new Font("Times New Roman", 1, 17));
        dataNama.setBounds(300, 120, 500, 30);
        dataNama.setVisible(true);
        this.add(dataNama);

        labelProdi = new JLabel("Program Studi / Fakultas : ");
        labelProdi.setBounds(70, 160, 230, 30);
        labelProdi.setFont(new Font("Times New Roman", 1, 18));
        labelProdi.setVisible(true);
        this.add(labelProdi);

        String prodi[] = {"Teknik Informatika(S1)", "Teknik Mesin(S1)", "Teknik Elektro(S1)", "Matematika(S1)", "Psikologi(S1)", "Farmasi(S1)", "Pend.Matematika(S1)", "Teologi(S1)", "Pend.Biologi(S1)", "Pend.Fisika(S1)", "Pend.Akutansi(S1)", "Pend.Ekonomi(S1)", "Pend.Bahasa Inggris(S1)", "Pend.Bahasa Sastra Indonesia Daerah(S1)",
            "Pend.Guru Sekolah Dasar(S1)", "Pend.Sejarah(S1)", "Pend.Agama Katholik(S1)", "Bimbingan Konseling(S1)", "Sastra Inggris(S1)",
            "Sastra Indonesia", "Ilmu Sejarah(S1)", "Akutansi(S1)", "Manajemen(S1)"};
        dataProdi = new JComboBox(prodi);
        dataProdi.setBounds(300, 160, 270, 30);
        add(dataProdi);

        String fakultas[] = {"Sains dan Teknologi", "Farmasi", "Psikologi", "Sastra", "Teologi",
            "Keguruan dan Ilmu Pendidikan", "Ekonomi"};
        dataFakultas = new JComboBox(fakultas);
        dataFakultas.setBounds(580, 160, 200, 30);
        add(dataFakultas);


        labelNomorHP = new JLabel("Nomor Handphone : ");
        labelNomorHP.setBounds(70, 200, 230, 30);
        labelNomorHP.setFont(new Font("Times New Roman", 1, 18));
        labelNomorHP.setVisible(true);
        this.add(labelNomorHP);

        dataNomorHP = new JTextField();
        dataNomorHP.setSize(15, 100);
        dataNomorHP.setFont(new Font("Times New Roman", 1, 17));
        dataNomorHP.setBounds(300, 200, 120, 30);
        dataNomorHP.setVisible(true);
        this.add(dataNomorHP);


        labelPeriode = new JLabel("Periode Yudisium (YYYY) : ");
        labelPeriode.setBounds(70, 240, 230, 30);
        labelPeriode.setFont(new Font("Times New Roman", 1, 18));
        labelPeriode.setVisible(true);
        this.add(labelPeriode);

        dataPeriode = new JTextField();
        dataPeriode.setSize(15, 100);
        dataPeriode.setFont(new Font("Times New Roman", 1, 17));
        dataPeriode.setBounds(300, 240, 65, 30);
        dataPeriode.setVisible(true);
        this.add(dataPeriode);

        kelengkapan = new JLabel("Kelengkapan Yudisium : ");
        kelengkapan.setBounds(70, 280, 230, 30);
        kelengkapan.setFont(new Font("Times New Roman", 1, 18));
        kelengkapan.setVisible(true);
        this.add(kelengkapan);

        daftarNilai = new JCheckBox();
        daftarNilai.setBounds(300, 285, 20, 20);
        daftarNilai.setVisible(true);
        this.add(daftarNilai);

        labelNilai = new JLabel("Daftar Nilai");
        labelNilai.setBounds(330, 270, 300, 50);
        labelNilai.setFont(new Font("Times New Roman", 1, 16));
        labelNilai.setVisible(true);
        this.add(labelNilai);

        naskahTA = new JCheckBox();
        naskahTA.setBounds(300, 335, 20, 20);
        naskahTA.setVisible(true);
        this.add(naskahTA);

        labelNaskahTA = new JLabel("Naskah Tugas Akhir");
        labelNaskahTA.setBounds(330, 320, 300, 50);
        labelNaskahTA.setFont(new Font("Times New Roman", 1, 16));
        labelNaskahTA.setVisible(true);
        this.add(labelNaskahTA);

        buktiKP = new JCheckBox();
        buktiKP.setBounds(300, 385, 20, 20);
        buktiKP.setVisible(true);
        this.add(buktiKP);

        labelBuktiKP = new JLabel("Bukti Kerja Praktek");
        labelBuktiKP.setBounds(330, 370, 200, 50);
        labelBuktiKP.setFont(new Font("Times New Roman", 1, 16));
        labelBuktiKP.setVisible(true);
        this.add(labelBuktiKP);

        bebasPinjamDosen = new JCheckBox();
        bebasPinjamDosen.setBounds(550, 285, 20, 20);
        bebasPinjamDosen.setVisible(true);
        this.add(bebasPinjamDosen);

        labelPinjamDosen = new JLabel("Bebas Pinjam dari Dosen");
        labelPinjamDosen.setBounds(580, 270, 200, 50);
        labelPinjamDosen.setFont(new Font("Times New Roman", 1, 16));
        labelPinjamDosen.setVisible(true);
        this.add(labelPinjamDosen);

        bebasPinjamLab = new JCheckBox();
        bebasPinjamLab.setBounds(550, 335, 20, 20);
        bebasPinjamLab.setVisible(true);
        this.add(bebasPinjamLab);

        labelPinjamLab = new JLabel("Bebas Pinjam dari Laboratorium");
        labelPinjamLab.setBounds(580, 320, 300, 50);
        labelPinjamLab.setFont(new Font("Times New Roman", 1, 16));
        labelPinjamLab.setVisible(true);
        this.add(labelPinjamLab);

        suratKetKKLKI = new JCheckBox();
        suratKetKKLKI.setBounds(550, 385, 20, 20);
        suratKetKKLKI.setVisible(true);
        this.add(suratKetKKLKI);

        labelSurat = new JLabel("Surat Keterangan KKL / KI");
        labelSurat.setBounds(580, 370, 200, 50);
        labelSurat.setFont(new Font("Times New Roman", 1, 16));
        labelSurat.setVisible(true);
        this.add(labelSurat);

        labelUpload = new JLabel("File Keterangan Bebas Pinjam >>> ");
        labelUpload.setBounds(70, 420, 300, 50);
        labelUpload.setFont(new Font("Times New Roman", 1, 18));
        labelUpload.setVisible(true);
        this.add(labelUpload);

        upload = new JButton("UPLOAD");
        upload.setBounds(380, 430, 100, 30);
        upload.setFont(new Font("Times New Roman", 1, 14));
        upload.setVisible(true);
        this.add(upload);
        upload.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                uploadFile = new JFileChooser();
                File file, directory;
                int status = uploadFile.showSaveDialog(null);
                if (status == JFileChooser.APPROVE_OPTION) {
                    file = uploadFile.getSelectedFile();
                    directory = uploadFile.getCurrentDirectory();

                    System.out.println("Directory : " + directory.getName());
                    System.out.println("File selected for saving data : " + file.getName());
                    System.out.println("Full path name : " + file.getAbsolutePath());
                    JTextField path = new JTextField();
                    path.setText(file.getAbsolutePath());
                    path.setFont(new Font("Times New Roman", 1, 14));
                    path.setEditable(true);
                    path.setBounds(100, 720, 250, 33);
                    path.setBounds(70, 460, 300, 30);
                    add(path);
                } else {
                    JOptionPane.showMessageDialog(null, "Save File Dialog Canceled");
                }
            }
        });

        save = new JButton("Save");
        save.setBounds(500, 480, 100, 40);
        save.setFont(new Font("Broadway", 1, 16));
        save.setBackground(Color.CYAN);
        this.add(save);
        save.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "Your Input Data is SAVE");
                try {
                    save();
                } catch (IOException ex) {
                    Logger.getLogger(PanelDaftarYudisium.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
//            private void simpanData() throws Exception {
//            }
        });

        cancel = new JButton("Cancel");
        cancel.setBounds(630, 480, 100, 40);
        cancel.setFont(new Font("Broadway", 1, 16));
        cancel.setBackground(Color.CYAN);
        this.add(cancel);
        cancel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "Your Input Data is CANCEL");
                FrameUtamaMahasiswa frame = new FrameUtamaMahasiswa();
                frame.setVisible(true);
                setVisible(false);
            }
        });
    }

    public void save() throws IOException {
        Yudisium yudi = new Yudisium();
        String nim = dataNim.getText();
        yudi.setNim(nim);
        String nama = dataNama.getText();
        yudi.setNama(nama);
        String prodi = dataProdi.getName();
        yudi.setProdi(prodi);
        String fakultas = dataFakultas.getName();
        yudi.setFakultas(fakultas);
        String periodeYudisium = dataPeriode.getText();
        yudi.setPeriodeYudisium(periodeYudisium);
        Sekretariat.tambahYudisium(yudi);
//        Sekretariat.simpanYudisium();
//        JOptionPane.showMessageDialog(null, Sekretariat.bacaNIMYudisium(),"info",1);

        if (naskahTA.isSelected() == false) {
            JOptionPane.showMessageDialog(null, "Maaf, Lembar Naskah Tugas Akhir HARUS ADA");
        } else {
            if (daftarNilai.isSelected() == true && naskahTA.isSelected() == true
                    && bebasPinjamLab.isSelected() == true && bebasPinjamDosen.isSelected() == true
                    && buktiKP.isSelected() == true && suratKetKKLKI.isSelected() == true) {

                daftarNilai.setText("Ada");
                naskahTA.setText("Ada");
                bebasPinjamLab.setText("Ada");
                bebasPinjamDosen.setText("Ada");
                buktiKP.setText("Ada");
                suratKetKKLKI.setText("Ada");

                JOptionPane.showMessageDialog(null, "*** Data dan Lampiran Lengkap ***");
            } else {
                JOptionPane.showMessageDialog(null, "!!! Data dan Lampiran Belum Lengkap !!!");
            }
        }
    }
}
